# -*- coding: utf-8 -*-
"""
Created on Wed Apr  3 10:14:08 2024

@author: 刘翼
"""

import cv2
import numpy as np
from matplotlib import pyplot as plt
# 腐蚀
img = cv2.imread(r"C:\Users\Public\opencv\Figure\car.png",0)
kernel = np.ones((3,3),np.uint8)
erosion = cv2.erode(img,kernel,iterations = 1)
plt.figure('erode',figsize=(8,8))
plt.subplot(121)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)
plt.axis('off')
plt.subplot(122)
plt.title('erode image')
plt.imshow(erosion,plt.cm.gray)
plt.axis('off')

# 膨胀
dilation = cv2.dilate(img,kernel,iterations = 1)
plt.figure('erode',figsize=(8,8))
plt.subplot(223)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)
plt.axis('off')
plt.subplot(224)
plt.title(' dilate image')
plt.imshow(dilation,plt.cm.gray)
plt.axis('off')
